<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE CPP #-}</span><span>
</span><span id="line-2"></span><span>
</span><span id="line-3"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">GHC.Stg.Subst</span><span> </span><span class="hs-keyword">where</span><span class="hs-cpp">

#include &quot;HsVersions.h&quot;
</span><span>
</span><span id="line-7"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Prelude.html"><span class="hs-identifier">GHC.Prelude</span></a></span><span>
</span><span id="line-8"></span><span>
</span><span id="line-9"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Id.html"><span class="hs-identifier">GHC.Types.Id</span></a></span><span>
</span><span id="line-10"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Var.Env.html"><span class="hs-identifier">GHC.Types.Var.Env</span></a></span><span>
</span><span id="line-11"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../transformers/src/Control.Monad.Trans.State.Strict.html#"><span class="hs-identifier">Control.Monad.Trans.State.Strict</span></a></span><span>
</span><span id="line-12"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html"><span class="hs-identifier">GHC.Utils.Outputable</span></a></span><span>
</span><span id="line-13"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Misc.html"><span class="hs-identifier">GHC.Utils.Misc</span></a></span><span>
</span><span id="line-14"></span><span>
</span><span id="line-15"></span><span class="hs-comment">-- | A renaming substitution from 'Id's to 'Id's. Like 'RnEnv2', but not</span><span>
</span><span id="line-16"></span><span class="hs-comment">-- maintaining pairs of substitutions. Like 'GHC.Core.Subst.Subst', but</span><span>
</span><span id="line-17"></span><span class="hs-comment">-- with the domain being 'Id's instead of entire 'CoreExpr'.</span><span>
</span><span id="line-18"></span><span class="hs-keyword">data</span><span> </span><span id="Subst"><span class="annot"><a href="GHC.Stg.Subst.html#Subst"><span class="hs-identifier hs-var">Subst</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="Subst"><span class="annot"><a href="GHC.Stg.Subst.html#Subst"><span class="hs-identifier hs-var">Subst</span></a></span></span><span> </span><span class="annot"><a href="GHC.Types.Var.Env.html#InScopeSet"><span class="hs-identifier hs-type">InScopeSet</span></a></span><span> </span><span class="annot"><a href="GHC.Stg.Subst.html#IdSubstEnv"><span class="hs-identifier hs-type">IdSubstEnv</span></a></span><span>
</span><span id="line-19"></span><span>
</span><span id="line-20"></span><span class="hs-keyword">type</span><span> </span><span id="IdSubstEnv"><span class="annot"><a href="GHC.Stg.Subst.html#IdSubstEnv"><span class="hs-identifier hs-var">IdSubstEnv</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><a href="GHC.Types.Var.Env.html#IdEnv"><span class="hs-identifier hs-type">IdEnv</span></a></span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span>
</span><span id="line-21"></span><span>
</span><span id="line-22"></span><span class="hs-comment">-- | @emptySubst = 'mkEmptySubst' 'emptyInScopeSet'@</span><span>
</span><span id="line-23"></span><span class="annot"><a href="GHC.Stg.Subst.html#emptySubst"><span class="hs-identifier hs-type">emptySubst</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Stg.Subst.html#Subst"><span class="hs-identifier hs-type">Subst</span></a></span><span>
</span><span id="line-24"></span><span id="emptySubst"><span class="annot"><span class="annottext">emptySubst :: Subst
</span><a href="GHC.Stg.Subst.html#emptySubst"><span class="hs-identifier hs-var hs-var">emptySubst</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">InScopeSet -&gt; Subst
</span><a href="GHC.Stg.Subst.html#mkEmptySubst"><span class="hs-identifier hs-var">mkEmptySubst</span></a></span><span> </span><span class="annot"><span class="annottext">InScopeSet
</span><a href="GHC.Types.Var.Env.html#emptyInScopeSet"><span class="hs-identifier hs-var">emptyInScopeSet</span></a></span><span>
</span><span id="line-25"></span><span>
</span><span id="line-26"></span><span class="hs-comment">-- | Constructs a new 'Subst' assuming the variables in the given 'InScopeSet'</span><span>
</span><span id="line-27"></span><span class="hs-comment">-- are in scope.</span><span>
</span><span id="line-28"></span><span class="annot"><a href="GHC.Stg.Subst.html#mkEmptySubst"><span class="hs-identifier hs-type">mkEmptySubst</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Var.Env.html#InScopeSet"><span class="hs-identifier hs-type">InScopeSet</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Stg.Subst.html#Subst"><span class="hs-identifier hs-type">Subst</span></a></span><span>
</span><span id="line-29"></span><span id="mkEmptySubst"><span class="annot"><span class="annottext">mkEmptySubst :: InScopeSet -&gt; Subst
</span><a href="GHC.Stg.Subst.html#mkEmptySubst"><span class="hs-identifier hs-var hs-var">mkEmptySubst</span></a></span></span><span> </span><span id="local-6989586621680951186"><span class="annot"><span class="annottext">InScopeSet
</span><a href="#local-6989586621680951186"><span class="hs-identifier hs-var">in_scope</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">InScopeSet -&gt; IdSubstEnv -&gt; Subst
</span><a href="GHC.Stg.Subst.html#Subst"><span class="hs-identifier hs-var">Subst</span></a></span><span> </span><span class="annot"><span class="annottext">InScopeSet
</span><a href="#local-6989586621680951186"><span class="hs-identifier hs-var">in_scope</span></a></span><span> </span><span class="annot"><span class="annottext">IdSubstEnv
forall a. VarEnv a
</span><a href="GHC.Types.Var.Env.html#emptyVarEnv"><span class="hs-identifier hs-var">emptyVarEnv</span></a></span><span>
</span><span id="line-30"></span><span>
</span><span id="line-31"></span><span class="hs-comment">-- | Substitutes an 'Id' for another one according to the 'Subst' given in a way</span><span>
</span><span id="line-32"></span><span class="hs-comment">-- that avoids shadowing the 'InScopeSet', returning the result and an updated</span><span>
</span><span id="line-33"></span><span class="hs-comment">-- 'Subst' that should be used by subsequent substitutions.</span><span>
</span><span id="line-34"></span><span class="annot"><a href="GHC.Stg.Subst.html#substBndr"><span class="hs-identifier hs-type">substBndr</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Stg.Subst.html#Subst"><span class="hs-identifier hs-type">Subst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Stg.Subst.html#Subst"><span class="hs-identifier hs-type">Subst</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-35"></span><span id="substBndr"><span class="annot"><span class="annottext">substBndr :: Id -&gt; Subst -&gt; (Id, Subst)
</span><a href="GHC.Stg.Subst.html#substBndr"><span class="hs-identifier hs-var hs-var">substBndr</span></a></span></span><span> </span><span id="local-6989586621680951183"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951183"><span class="hs-identifier hs-var">id</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Stg.Subst.html#Subst"><span class="hs-identifier hs-type">Subst</span></a></span><span> </span><span id="local-6989586621680951182"><span class="annot"><span class="annottext">InScopeSet
</span><a href="#local-6989586621680951182"><span class="hs-identifier hs-var">in_scope</span></a></span></span><span> </span><span id="local-6989586621680951181"><span class="annot"><span class="annottext">IdSubstEnv
</span><a href="#local-6989586621680951181"><span class="hs-identifier hs-var">env</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-36"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951180"><span class="hs-identifier hs-var">new_id</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">InScopeSet -&gt; IdSubstEnv -&gt; Subst
</span><a href="GHC.Stg.Subst.html#Subst"><span class="hs-identifier hs-var">Subst</span></a></span><span> </span><span class="annot"><span class="annottext">InScopeSet
</span><a href="#local-6989586621680951179"><span class="hs-identifier hs-var">new_in_scope</span></a></span><span> </span><span class="annot"><span class="annottext">IdSubstEnv
</span><a href="#local-6989586621680951178"><span class="hs-identifier hs-var">new_env</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-37"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-38"></span><span>    </span><span id="local-6989586621680951180"><span class="annot"><span class="annottext">new_id :: Id
</span><a href="#local-6989586621680951180"><span class="hs-identifier hs-var hs-var">new_id</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">InScopeSet -&gt; Id -&gt; Id
</span><a href="GHC.Types.Var.Env.html#uniqAway"><span class="hs-identifier hs-var">uniqAway</span></a></span><span> </span><span class="annot"><span class="annottext">InScopeSet
</span><a href="#local-6989586621680951182"><span class="hs-identifier hs-var">in_scope</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951183"><span class="hs-identifier hs-var">id</span></a></span><span>
</span><span id="line-39"></span><span>    </span><span id="local-6989586621680951174"><span class="annot"><span class="annottext">no_change :: Bool
</span><a href="#local-6989586621680951174"><span class="hs-identifier hs-var hs-var">no_change</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951180"><span class="hs-identifier hs-var">new_id</span></a></span><span> </span><span class="annot"><span class="annottext">Id -&gt; Id -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951183"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="hs-comment">-- in case nothing shadowed</span><span>
</span><span id="line-40"></span><span>    </span><span id="local-6989586621680951179"><span class="annot"><span class="annottext">new_in_scope :: InScopeSet
</span><a href="#local-6989586621680951179"><span class="hs-identifier hs-var hs-var">new_in_scope</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">InScopeSet
</span><a href="#local-6989586621680951182"><span class="hs-identifier hs-var">in_scope</span></a></span><span> </span><span class="annot"><span class="annottext">InScopeSet -&gt; Id -&gt; InScopeSet
</span><a href="GHC.Types.Var.Env.html#extendInScopeSet"><span class="hs-operator hs-var">`extendInScopeSet`</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951180"><span class="hs-identifier hs-var">new_id</span></a></span><span>
</span><span id="line-41"></span><span>    </span><span id="local-6989586621680951178"><span class="annot"><span class="annottext">new_env :: IdSubstEnv
</span><a href="#local-6989586621680951178"><span class="hs-identifier hs-var hs-var">new_env</span></a></span></span><span>
</span><span id="line-42"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680951174"><span class="hs-identifier hs-var">no_change</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IdSubstEnv -&gt; Id -&gt; IdSubstEnv
forall a. VarEnv a -&gt; Id -&gt; VarEnv a
</span><a href="GHC.Types.Var.Env.html#delVarEnv"><span class="hs-identifier hs-var">delVarEnv</span></a></span><span> </span><span class="annot"><span class="annottext">IdSubstEnv
</span><a href="#local-6989586621680951181"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951183"><span class="hs-identifier hs-var">id</span></a></span><span>
</span><span id="line-43"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IdSubstEnv -&gt; Id -&gt; Id -&gt; IdSubstEnv
forall a. VarEnv a -&gt; Id -&gt; a -&gt; VarEnv a
</span><a href="GHC.Types.Var.Env.html#extendVarEnv"><span class="hs-identifier hs-var">extendVarEnv</span></a></span><span> </span><span class="annot"><span class="annottext">IdSubstEnv
</span><a href="#local-6989586621680951181"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951183"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951180"><span class="hs-identifier hs-var">new_id</span></a></span><span>
</span><span id="line-44"></span><span>
</span><span id="line-45"></span><span class="hs-comment">-- | @substBndrs = runState . traverse (state . substBndr)@</span><span>
</span><span id="line-46"></span><span id="local-6989586621680951225"><span class="annot"><a href="GHC.Stg.Subst.html#substBndrs"><span class="hs-identifier hs-type">substBndrs</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/Data.Traversable.html#Traversable"><span class="hs-identifier hs-type">Traversable</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680951225"><span class="hs-identifier hs-type">f</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="#local-6989586621680951225"><span class="hs-identifier hs-type">f</span></a></span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Stg.Subst.html#Subst"><span class="hs-identifier hs-type">Subst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621680951225"><span class="hs-identifier hs-type">f</span></a></span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Stg.Subst.html#Subst"><span class="hs-identifier hs-type">Subst</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-47"></span><span id="substBndrs"><span class="annot"><span class="annottext">substBndrs :: forall (f :: * -&gt; *).
Traversable f =&gt;
f Id -&gt; Subst -&gt; (f Id, Subst)
</span><a href="GHC.Stg.Subst.html#substBndrs"><span class="hs-identifier hs-var hs-var">substBndrs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">State Subst (f Id) -&gt; Subst -&gt; (f Id, Subst)
forall s a. State s a -&gt; s -&gt; (a, s)
</span><a href="../../transformers/src/Control.Monad.Trans.State.Strict.html#runState"><span class="hs-identifier hs-var">runState</span></a></span><span> </span><span class="annot"><span class="annottext">(State Subst (f Id) -&gt; Subst -&gt; (f Id, Subst))
-&gt; (f Id -&gt; State Subst (f Id)) -&gt; f Id -&gt; Subst -&gt; (f Id, Subst)
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">(Id -&gt; StateT Subst Identity Id) -&gt; f Id -&gt; State Subst (f Id)
forall (t :: * -&gt; *) (f :: * -&gt; *) a b.
(Traversable t, Applicative f) =&gt;
(a -&gt; f b) -&gt; t a -&gt; f (t b)
</span><a href="../../base/src/Data.Traversable.html#traverse"><span class="hs-identifier hs-var">traverse</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Subst -&gt; (Id, Subst)) -&gt; StateT Subst Identity Id
forall (m :: * -&gt; *) s a. Monad m =&gt; (s -&gt; (a, s)) -&gt; StateT s m a
</span><a href="../../transformers/src/Control.Monad.Trans.State.Strict.html#state"><span class="hs-identifier hs-var">state</span></a></span><span> </span><span class="annot"><span class="annottext">((Subst -&gt; (Id, Subst)) -&gt; StateT Subst Identity Id)
-&gt; (Id -&gt; Subst -&gt; (Id, Subst)) -&gt; Id -&gt; StateT Subst Identity Id
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">Id -&gt; Subst -&gt; (Id, Subst)
</span><a href="GHC.Stg.Subst.html#substBndr"><span class="hs-identifier hs-var">substBndr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-48"></span><span>
</span><span id="line-49"></span><span class="hs-comment">-- | Substitutes an occurrence of an identifier for its counterpart recorded</span><span>
</span><span id="line-50"></span><span class="hs-comment">-- in the 'Subst'.</span><span>
</span><span id="line-51"></span><span class="annot"><a href="GHC.Stg.Subst.html#lookupIdSubst"><span class="hs-identifier hs-type">lookupIdSubst</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Stack.Types.html#HasCallStack"><span class="hs-identifier hs-type">HasCallStack</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Stg.Subst.html#Subst"><span class="hs-identifier hs-type">Subst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span>
</span><span id="line-52"></span><span id="lookupIdSubst"><span class="annot"><span class="annottext">lookupIdSubst :: HasCallStack =&gt; Id -&gt; Subst -&gt; Id
</span><a href="GHC.Stg.Subst.html#lookupIdSubst"><span class="hs-identifier hs-var hs-var">lookupIdSubst</span></a></span></span><span> </span><span id="local-6989586621680951150"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951150"><span class="hs-identifier hs-var">id</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Stg.Subst.html#Subst"><span class="hs-identifier hs-type">Subst</span></a></span><span> </span><span id="local-6989586621680951149"><span class="annot"><span class="annottext">InScopeSet
</span><a href="#local-6989586621680951149"><span class="hs-identifier hs-var">in_scope</span></a></span></span><span> </span><span id="local-6989586621680951148"><span class="annot"><span class="annottext">IdSubstEnv
</span><a href="#local-6989586621680951148"><span class="hs-identifier hs-var">env</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-53"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; Bool
</span><a href="GHC.Types.Var.html#isLocalId"><span class="hs-identifier hs-var">isLocalId</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951150"><span class="hs-identifier hs-var">id</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951150"><span class="hs-identifier hs-var">id</span></a></span><span>
</span><span id="line-54"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680951145"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951145"><span class="hs-identifier hs-var">id'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IdSubstEnv -&gt; Id -&gt; Maybe Id
forall a. VarEnv a -&gt; Id -&gt; Maybe a
</span><a href="GHC.Types.Var.Env.html#lookupVarEnv"><span class="hs-identifier hs-var">lookupVarEnv</span></a></span><span> </span><span class="annot"><span class="annottext">IdSubstEnv
</span><a href="#local-6989586621680951148"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951150"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951145"><span class="hs-identifier hs-var">id'</span></a></span><span>
</span><span id="line-55"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680951143"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951143"><span class="hs-identifier hs-var">id'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">InScopeSet -&gt; Id -&gt; Maybe Id
</span><a href="GHC.Types.Var.Env.html#lookupInScope"><span class="hs-identifier hs-var">lookupInScope</span></a></span><span> </span><span class="annot"><span class="annottext">InScopeSet
</span><a href="#local-6989586621680951149"><span class="hs-identifier hs-var">in_scope</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951150"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951143"><span class="hs-identifier hs-var">id'</span></a></span><span>
</span><span id="line-56"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">WARN</span><span class="hs-special">(</span><span> </span><span class="hs-identifier">True</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">text</span><span> </span><span class="hs-string">&quot;StgSubst.lookupIdSubst&quot;</span><span> </span><span class="hs-operator">&lt;+&gt;</span><span> </span><span class="hs-identifier">ppr</span><span> </span><span class="hs-identifier">id</span><span> </span><span class="hs-operator">$$</span><span> </span><span class="hs-identifier">ppr</span><span> </span><span class="hs-identifier">in_scope</span><span class="hs-special">)</span><span>
</span><span id="line-57"></span><span>                </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951150"><span class="hs-identifier hs-var">id</span></a></span><span>
</span><span id="line-58"></span><span>
</span><span id="line-59"></span><span class="hs-comment">-- | Substitutes an occurrence of an identifier for its counterpart recorded</span><span>
</span><span id="line-60"></span><span class="hs-comment">-- in the 'Subst'. Does not generate a debug warning if the identifier to</span><span>
</span><span id="line-61"></span><span class="hs-comment">-- to substitute wasn't in scope.</span><span>
</span><span id="line-62"></span><span class="annot"><a href="GHC.Stg.Subst.html#noWarnLookupIdSubst"><span class="hs-identifier hs-type">noWarnLookupIdSubst</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Stack.Types.html#HasCallStack"><span class="hs-identifier hs-type">HasCallStack</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Stg.Subst.html#Subst"><span class="hs-identifier hs-type">Subst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span>
</span><span id="line-63"></span><span id="noWarnLookupIdSubst"><span class="annot"><span class="annottext">noWarnLookupIdSubst :: HasCallStack =&gt; Id -&gt; Subst -&gt; Id
</span><a href="GHC.Stg.Subst.html#noWarnLookupIdSubst"><span class="hs-identifier hs-var hs-var">noWarnLookupIdSubst</span></a></span></span><span> </span><span id="local-6989586621680951134"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951134"><span class="hs-identifier hs-var">id</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Stg.Subst.html#Subst"><span class="hs-identifier hs-type">Subst</span></a></span><span> </span><span id="local-6989586621680951133"><span class="annot"><span class="annottext">InScopeSet
</span><a href="#local-6989586621680951133"><span class="hs-identifier hs-var">in_scope</span></a></span></span><span> </span><span id="local-6989586621680951132"><span class="annot"><span class="annottext">IdSubstEnv
</span><a href="#local-6989586621680951132"><span class="hs-identifier hs-var">env</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-64"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Id -&gt; Bool
</span><a href="GHC.Types.Var.html#isLocalId"><span class="hs-identifier hs-var">isLocalId</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951134"><span class="hs-identifier hs-var">id</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951134"><span class="hs-identifier hs-var">id</span></a></span><span>
</span><span id="line-65"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680951131"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951131"><span class="hs-identifier hs-var">id'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IdSubstEnv -&gt; Id -&gt; Maybe Id
forall a. VarEnv a -&gt; Id -&gt; Maybe a
</span><a href="GHC.Types.Var.Env.html#lookupVarEnv"><span class="hs-identifier hs-var">lookupVarEnv</span></a></span><span> </span><span class="annot"><span class="annottext">IdSubstEnv
</span><a href="#local-6989586621680951132"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951134"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951131"><span class="hs-identifier hs-var">id'</span></a></span><span>
</span><span id="line-66"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680951130"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951130"><span class="hs-identifier hs-var">id'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">InScopeSet -&gt; Id -&gt; Maybe Id
</span><a href="GHC.Types.Var.Env.html#lookupInScope"><span class="hs-identifier hs-var">lookupInScope</span></a></span><span> </span><span class="annot"><span class="annottext">InScopeSet
</span><a href="#local-6989586621680951133"><span class="hs-identifier hs-var">in_scope</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951134"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951130"><span class="hs-identifier hs-var">id'</span></a></span><span>
</span><span id="line-67"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951134"><span class="hs-identifier hs-var">id</span></a></span><span>
</span><span id="line-68"></span><span>
</span><span id="line-69"></span><span class="hs-comment">-- | Add the 'Id' to the in-scope set and remove any existing substitutions for</span><span>
</span><span id="line-70"></span><span class="hs-comment">-- it.</span><span>
</span><span id="line-71"></span><span class="annot"><a href="GHC.Stg.Subst.html#extendInScope"><span class="hs-identifier hs-type">extendInScope</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Stg.Subst.html#Subst"><span class="hs-identifier hs-type">Subst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Stg.Subst.html#Subst"><span class="hs-identifier hs-type">Subst</span></a></span><span>
</span><span id="line-72"></span><span id="extendInScope"><span class="annot"><span class="annottext">extendInScope :: Id -&gt; Subst -&gt; Subst
</span><a href="GHC.Stg.Subst.html#extendInScope"><span class="hs-identifier hs-var hs-var">extendInScope</span></a></span></span><span> </span><span id="local-6989586621680951128"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951128"><span class="hs-identifier hs-var">id</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Stg.Subst.html#Subst"><span class="hs-identifier hs-type">Subst</span></a></span><span> </span><span id="local-6989586621680951127"><span class="annot"><span class="annottext">InScopeSet
</span><a href="#local-6989586621680951127"><span class="hs-identifier hs-var">in_scope</span></a></span></span><span> </span><span id="local-6989586621680951126"><span class="annot"><span class="annottext">IdSubstEnv
</span><a href="#local-6989586621680951126"><span class="hs-identifier hs-var">env</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">InScopeSet -&gt; IdSubstEnv -&gt; Subst
</span><a href="GHC.Stg.Subst.html#Subst"><span class="hs-identifier hs-var">Subst</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">InScopeSet
</span><a href="#local-6989586621680951127"><span class="hs-identifier hs-var">in_scope</span></a></span><span> </span><span class="annot"><span class="annottext">InScopeSet -&gt; Id -&gt; InScopeSet
</span><a href="GHC.Types.Var.Env.html#extendInScopeSet"><span class="hs-operator hs-var">`extendInScopeSet`</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951128"><span class="hs-identifier hs-var">id</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">IdSubstEnv
</span><a href="#local-6989586621680951126"><span class="hs-identifier hs-var">env</span></a></span><span>
</span><span id="line-73"></span><span>
</span><span id="line-74"></span><span class="hs-comment">-- | Add a substitution for an 'Id' to the 'Subst': you must ensure that the</span><span>
</span><span id="line-75"></span><span class="hs-comment">-- in-scope set is such that TyCoSubst Note [The substitution invariant]</span><span>
</span><span id="line-76"></span><span class="hs-comment">-- holds after extending the substitution like this.</span><span>
</span><span id="line-77"></span><span class="annot"><a href="GHC.Stg.Subst.html#extendSubst"><span class="hs-identifier hs-type">extendSubst</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Stg.Subst.html#Subst"><span class="hs-identifier hs-type">Subst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Stg.Subst.html#Subst"><span class="hs-identifier hs-type">Subst</span></a></span><span>
</span><span id="line-78"></span><span id="extendSubst"><span class="annot"><span class="annottext">extendSubst :: Id -&gt; Id -&gt; Subst -&gt; Subst
</span><a href="GHC.Stg.Subst.html#extendSubst"><span class="hs-identifier hs-var hs-var">extendSubst</span></a></span></span><span> </span><span id="local-6989586621680951124"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951124"><span class="hs-identifier hs-var">id</span></a></span></span><span> </span><span id="local-6989586621680951123"><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951123"><span class="hs-identifier hs-var">new_id</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Stg.Subst.html#Subst"><span class="hs-identifier hs-type">Subst</span></a></span><span> </span><span id="local-6989586621680951122"><span class="annot"><span class="annottext">InScopeSet
</span><a href="#local-6989586621680951122"><span class="hs-identifier hs-var">in_scope</span></a></span></span><span> </span><span id="local-6989586621680951121"><span class="annot"><span class="annottext">IdSubstEnv
</span><a href="#local-6989586621680951121"><span class="hs-identifier hs-var">env</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-79"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">ASSERT2</span><span class="hs-special">(</span><span> </span><span class="hs-identifier">new_id</span><span> </span><span class="hs-special">`</span><span class="hs-identifier">elemInScopeSet</span><span class="hs-special">`</span><span> </span><span class="hs-identifier">in_scope</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">ppr</span><span> </span><span class="hs-identifier">id</span><span> </span><span class="hs-operator">&lt;+&gt;</span><span> </span><span class="hs-identifier">ppr</span><span> </span><span class="hs-identifier">new_id</span><span> </span><span class="hs-operator">$$</span><span> </span><span class="hs-identifier">ppr</span><span> </span><span class="hs-identifier">in_scope</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-80"></span><span>    </span><span class="annot"><span class="annottext">InScopeSet -&gt; IdSubstEnv -&gt; Subst
</span><a href="GHC.Stg.Subst.html#Subst"><span class="hs-identifier hs-var">Subst</span></a></span><span> </span><span class="annot"><span class="annottext">InScopeSet
</span><a href="#local-6989586621680951122"><span class="hs-identifier hs-var">in_scope</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">IdSubstEnv -&gt; Id -&gt; Id -&gt; IdSubstEnv
forall a. VarEnv a -&gt; Id -&gt; a -&gt; VarEnv a
</span><a href="GHC.Types.Var.Env.html#extendVarEnv"><span class="hs-identifier hs-var">extendVarEnv</span></a></span><span> </span><span class="annot"><span class="annottext">IdSubstEnv
</span><a href="#local-6989586621680951121"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951124"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="annot"><span class="annottext">Id
</span><a href="#local-6989586621680951123"><span class="hs-identifier hs-var">new_id</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-81"></span></pre></body></html>